import dialog from "./dialog.js"
import auth from "./auth.js"
import router from "./router.js"
import store from "@/store/index.js"
// import {
// 	logout,
// 	getUserInfoByCode
// } from '@/api/module/account.js';

const publicFun = {
	
	wxLogin(params) {
		return new Promise((resolve, reject) => {

			uni.login({
				provider: 'weixin',
				...params,
				success: res => {
					console.log('login', res)
					resolve(res)
				},
				fail: err => {
					reject(err)
				}
			})
		})
	},
	getOpenid() {
		return new Promise((resolve, reject) => {
			uni.login({
				provider: 'weixin',
				success: res => {
					console.log('weixin login response :', res)
					getUserInfoByCode({
						code: res.code,
					}).then(res => {
						console.log('getUserInfoByCode:', res)
						const result = res.result
						uni.getUserInfo({
							complete: res => {
								const wxInfo = {
									...res.userInfo,
									...result
								}
								this.$auth.setStorage({
									key: 'wxInfo',
									value: wxInfo
								})
								resolve()
							}
						})
					})
				}
			})
		})
	}

}

export default publicFun;
